<?php

class Note extends AppModel {

	var $name = 'Note';
	var $belongsTo = array('From' => array('className' => 'Member', 'foreignKey' => 'from_id'));

	function getForMember($id, $del = null) {
		if ($del === null) {
			$delivery_id = Configure::read('Delivery.delivery_id');
		} else {
			$delivery_id = $del;
		}
		return $this->findAll('((Note.table_name = "members" AND Note.table_id = "' . $id . '") OR (Note.table_name = "basket_items" AND Note.table_id IN (SELECT basket_items.id FROM basket_items WHERE basket_items.member_id = ' . $id . '))) AND Note.delivery_id = ' . $delivery_id, null, 'Note.created');
	}
	
	function getForProducer($id, $del = null) {
		if ($del === null) {
			$delivery_id = Configure::read('Delivery.delivery_id');
		} else {
			$delivery_id = $del;
		}
		return $this->findAll('Note.table_name = "producers" AND Note.table_id = "' . $id . '" AND Note.delivery_id = ' . $delivery_id, null, 'Note.created');
	}

}

?>